package com.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.test.entity.dto.Notification;
import com.test.mapper.NotificationMapper;
import com.test.service.NotificationService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NotificationServiceImpl extends ServiceImpl<NotificationMapper, Notification> implements NotificationService {
    @Resource
    NotificationMapper notificationMapper;

    @Override
    public List<Notification> getNotifications(Integer uid) {
        return notificationMapper.selectList(new QueryWrapper<Notification>().eq("uid",uid).orderByDesc("time"));

    }

    @Override
    public void deleteOne(Integer id, Integer uid) {
        notificationMapper.delete(new QueryWrapper<Notification>().eq("id",id).eq("uid",uid));

    }

    @Override
    public void deleteAll(Integer uid) {
        notificationMapper.delete(new QueryWrapper<Notification>().eq("uid",uid));

    }

    @Override
    public void addNotification(Notification notification) {
        notificationMapper.insert(notification);

    }
}
